import * as IMApi from '@src/api/ImApi.js';
import {Message} from 'element-ui'
import i18n from '@src/locales'

/**
 * buildParams 构造消息参数
 */
class buildParams {
  constructor(data = {}) {
    this.conversationId = data.conversationId,
    this.messageType = data.messageType,
    this.messageContent = data.messageContent
  }
}

export async function customerServiceSendNewMessage(obj = {}){
  try {
    let messageType = obj.messageType
    if(!messageType){
      Message.error(i18n.t('im.imChat.components.messageBox.tips1'))
      return Promise.reject(i18n.t('im.imChat.components.messageBox.tips1'))
    }

    let params = new buildParams(obj)
   
    const { code, data, message } = await IMApi.customerServiceSendNewMessage(params)

    if (code == 0) {
      data.rightDisplay = true
      return Promise.resolve(data)
    }

    Message.error(message)
    return Promise.reject(message)
  } catch (err) {
    console.error(err, 'customerServiceSendNewMessage')
    return Promise.reject('customerServiceSendNewMessage请求失败')
  }
}